/*
 * addon_dllutil.h
 *
 *  Created on: 2010-1-7
 *      Author: gavinkwoe
 */

#ifndef ADDON_LLIST_H_
#define ADDON_LLIST_H_

#include "addon_features.h"
#include "addon_std.h"
#include "addon_objbase.h"

/*************************************************************************
* PROTOTYPE
*************************************************************************/

struct __struct_addon_llink;
typedef struct __struct_addon_llink			addon_llink_t;
typedef struct __struct_addon_llink *		addon_llink_ptr_t;

struct __struct_addon_llist;
typedef struct __struct_addon_llist			addon_llist_t;
typedef struct __struct_addon_llist *		addon_llist_ptr_t;

/*************************************************************************
* STRUCTURE
*************************************************************************/

struct __struct_addon_llink
{
	addon_llink_ptr_t	next;
	addon_llink_ptr_t	prev;
};

struct __struct_addon_llist
{
	unsigned long		count;
	addon_llink_ptr_t	head;
	addon_llink_ptr_t	tail;
};

/*************************************************************************
* EXPORTED FUNCTION
*************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

ADDON_IMPORT void				addon_ll_push_head( addon_llist_ptr_t list, addon_llink_ptr_t link );
ADDON_IMPORT void				addon_ll_push_tail( addon_llist_ptr_t list, addon_llink_ptr_t link );
ADDON_IMPORT addon_llink_ptr_t	addon_ll_pop_head( addon_llist_ptr_t list );
ADDON_IMPORT addon_llink_ptr_t	addon_ll_pop_tail( addon_llist_ptr_t list );

ADDON_IMPORT void				addon_ll_insert( addon_llist_ptr_t list, addon_llink_ptr_t pos, addon_llink_ptr_t link );
ADDON_IMPORT void				addon_ll_remove( addon_llist_ptr_t list, addon_llink_ptr_t link );
ADDON_IMPORT void				addon_ll_sort( addon_llist_ptr_t list, addon_cmp_fptr_t cmp_func );


#ifdef __cplusplus
}
#endif //extern "C"

/*************************************************************************
* MACRO
*************************************************************************/

#define ADDON_LLINK_INIT( __p ) \
		{ \
			(__p)->prev = NULL; \
			(__p)->next = NULL; \
		}

#define ADDON_LLIST_INIT( __p ) \
		{ \
			(__p)->count = 0; \
			(__p)->head = NULL; \
			(__p)->tail = NULL; \
		}

#endif /* #ifndef ADDON_LLIST_H_ */
